package com.example.demo1;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "Servlet2", value = "/Servlet2")
public class Servlet2 extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doPost(request,response);
        }
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            // 补齐，设置request的字符集编码
            request.setCharacterEncoding("utf-8");
            //获取参数username的结果赋值给username
            String username=request.getParameter("username");
            String password=request.getParameter("password");
            //获取参数hobby的结果赋值给hobbysq
            String[] hobbys=request.getParameterValues("hobby");

            String hobStr="";
            for(int i=0;i<hobbys.length;i++){
                hobStr=hobStr+hobbys[i]+",";
            }
            response.getWriter().println("用户名是："+username+
                    ",密码是："+password+",爱好是："+hobStr);
        }
    }


